package jsyf.oa.web.device;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.device.DeviceTypeFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by y on 2018/6/25.
 */
@Api(value = "设备类型接口", description = "设备类型接口")
@Controller
@RequestMapping("/deviceType")
public class DeviceTypeController {
    @Resource
    private DeviceTypeFacade deviceTypeFacade;

    @ResponseBody
    @RequestMapping(value = "/getDeviceTypeList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询设备类型",
            notes = "查询设备类型 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void getBrandList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.deviceTypeFacade.getDeviceTypeList(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }
    @ResponseBody
    @RequestMapping(value = "/delById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id逻辑删除设备类型",
            notes = "通过id逻辑删除设备类型 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "id:''", dataType = "String", paramType = "body")
    public void delById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.deviceTypeFacade.delById(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("isOk", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }
    @ResponseBody
    @RequestMapping(value = "/update.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改设备类型信息",
            notes = "修改设备类型信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "jsonData:''", dataType = "String", paramType = "body")
    public void update(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.deviceTypeFacade.update(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("isOk", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }
    @ResponseBody
    @RequestMapping(value = "/add.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "添加设备类型",
            notes = "添加设备类型 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void add(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonResult = new JSONObject();
        jsonResult.put("id",this.deviceTypeFacade.add(jsonData));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonResult));
    }
}
